package com.hethongviet.preventingmachine.helps.dialog;

import java.util.Timer;
import java.util.TimerTask;

import com.hethongviet.preventingmachine.R;

import android.app.Activity;
import android.app.Dialog;
import android.view.Window;
import android.widget.TextView;

public class DialogMessageTimeOut extends Dialog
{

	private TextView _textView = null;

	private Activity _activity = null;

	public DialogMessageTimeOut(Activity activity)
	{
		super(activity);
		_activity = activity;

		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.dialog_message_timeout);

		_textView = (TextView) findViewById(R.id.textDialogMessage);

	}

	/** Only message show */
	public DialogMessageTimeOut(Activity activity, int textId)
	{
		this(activity);
		prepareResource(activity.getString(textId));

	}

	public DialogMessageTimeOut(Activity activity, String text)
	{
		this(activity);
		prepareResource(text);

	}

	public DialogMessageTimeOut(Activity activity, String text,
			boolean isTimetaskAddedLater)
	{
		this(activity);
		prepareResource(text, true);

	}

	private void prepareResource(String text)
	{
		_textView.setText(text);

		final TimerTask timerTask = new TimerTask()
		{
			@Override
			public void run()
			{
				_activity.runOnUiThread(new Runnable()
				{
					@Override
					public void run()
					{
						hide();
					}
				});
			}
		};

		new Timer().schedule(timerTask, 3000);

	}

	private void prepareResource(String text, boolean isTimeTaskAddedLater)
	{
		_textView.setText(text);
	}

	public void setTimeTask(TimerTask timerTask)
	{
		new Timer().schedule(timerTask, 3000);
	}
	
}
